<style>
    .enleter {
        width: 300px;
        word-wrap: break-word;
        word-break: break-all;
    }
</style>
<div class="container-fluid">
    <div class="wrapper">
        <div class="panel">
            <div class="panel-body">
                <form action="__URL__/grabShipmentid" method="post">
                    <b style="color: red">应关务组（高玲玲、郑燚）和物流组（陈彦宇）要求，出口退税和非出口退税货物不能一起创建Shipmentid</b>
                    <div class="form-inline">
                        <b>帐号：</b>
                        <select class="chosen-select form-control" tabindex="-1" name="accountId"
                                data-name-group="common">
                            <option value="" class="empty-opt">-- 请选择 --</option>
                            <volist name="accounts" id="acc">
                                <option value="{$acc.id}"  <if condition="$postData.accountId eq $acc['id']">selected="selected"</if>>{$acc.name}</option>
                            </volist>
                        </select>
                        <b>Shipmentid：</b>
                        <input placeholder="输入Shipmentid" name="shipmentid" type="text" value="{$postData.shipmentid}" class="form-control">
                        <button class="btn btn-primary" type="submit">获取</button>
                    </div>
                </form>
                <hr>
                <notempty name="inboundShipments">
                <dl class="col-md-1">
                    <dt>Shipment name/ID</dt>
                    <dd>{$inboundShipments.Name}</dd>
                    <dd>{$inboundShipments.ShipmentName}</dd>
                </dl>
                <dl class="col-md-2">
                    <dt>Ship from</dt>
                    <dd>{$inboundShipments.ShipFromAddress.Name}</dd>
                    <dd>{$inboundShipments.ShipFromAddress.AddressLine1}</dd>
                    <if condition="$inboundShipments.ShipFromAddress.AddressLine2 neq ''">
                    <dd>{$inboundShipments.ShipFromAddress.AddressLine2}</dd>
                    </if>
                    <dd>{$inboundShipments.ShipFromAddress.City},{$inboundShipments.ShipFromAddress.StateOrProvinceCode}&nbsp;{$inboundShipments.ShipFromAddress.PostalCode}</dd>
                    <dd>{$inboundShipments.ShipFromAddress.CountryCode}</dd>
                </dl>
                <dl class="col-md-2">
                    <dt>Ship to</dt>
                    <empty name="shipToAddress">
                        DestinationCenterId：{$inboundShipments.DestinationFulfillmentCenterId}
                        <textarea id="shipToAddressDec"></textarea>
                    </empty>
                    <notempty name="shipToAddress">
                        <dd>{$shipToAddress.Name}</dd>
                        <dd>{$shipToAddress.AddressLine1}</dd>
                        <if condition="$shipToAddress.AddressLine2 neq ''">
                        <dd>{$shipToAddress.AddressLine2}</dd>
                        </if>
                        <dd>{$shipToAddress.City},{$shipToAddress.StateOrProvinceCode}&nbsp;{$shipToAddress.PostalCode}</dd>
                        <dd>{$shipToAddress.CountryCode}({$shipToAddress.CenterId})</dd>
                    </notempty>
                </dl>

                    <empty name="shipToAddress">
                    <dl class="col-md-3">
                        <img src="__PUBLIC__/images/shipToAddressCopyShow.png" />
                    </dl>
                    </empty>

                <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th width="140">sellerSku</th>
                        <th>title</th>
                        <th width="130">fnsku</th>
                        <th width="130">asin</th>
                        <th width="40">QuantityShipped</th>
                        <th width="90">sku</th>
                        <th>中文名称</th>
                        <th>是否单独发货</th>
                        <th>需求申请对应</th>
                    </tr>
                    </thead>
                    <tbody>
                    <volist name="shipmentItems" id="item">
                        <tr>
                        <td>{$item.seller_sku}</td>
                        <td class="enleter">{$item.title}</td>
                        <td>{$item.fnsku}</td>
                        <td>{$item.asin}</td>
                        <td>{$item.quantity}</td>
                        <td>{$item.sku}</td>
                        <if condition="$item.exception neq 1">
                            <td>{$item.sku_name}</td>
                            <td><if condition="$item.single_ship eq 1">是<else />否</if></td>
                            <td>
                                <volist name="item['radios']" id="radio">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="{$item.seller_sku}" class="needsDetailId"  value="{$radio['value']}" <if condition="$item.needsCount eq 1">checked</if> />
                                            {$radio['valueStr']}
                                        </label>
                                    </div>
                                </volist>
                            </td>
                            <else />
                            <td colspan="3" <if condition="$item.exception eq 1">class="text-danger"</if>><b>注意：以下原因导致本次获取失败：<br/>{$item.exceptionMsg}</b></td>
                        </if>
                    </tr>
                    </volist>
                </table>
                <if condition="$shipmentOk eq 1">
                <div class="fixed-table-toolbar col-md-offset-6">
                    <input type="text" id="remark" class="form-control" placeholder="输入Shipmentid的运输方式"><br/>
                    <button type="button" class="btn btn-info grabSubmit">提交结果</button>
                    <button type="button" class="btn btn-info grabSubmit pushWarehouseFlag">提交并推送仓库</button>
                </div>
                </if>
                </notempty>
                <div class="clearfix clear"></div>
            </div>
        </div>
    </div>
</div>

<script>
    $(".grabSubmit").click(function() {
        var shipToAddressDec = '';
        if($("#shipToAddressDec").length > 0) {
            shipToAddressDec = $("#shipToAddressDec").val();
            if(shipToAddressDec == '') {
                alert("请输入FBA目的仓地址，参考地址输入框右侧图片");
                return false;
            }
        }

        var eachTrRadioChecked = true;
        var needsDetailIdStr = Array();
        $(".needsDetailId").each(function(){
            var trRadioName = $(this).attr('name');
            var trRadioChecked = $('input:radio[name="'+ trRadioName +'"]:checked').val();
            if(trRadioChecked == null){
                eachTrRadioChecked = false;
                alert("请选择SKU：" + trRadioName + "对应的需求!");
                return false;
            }
            if ($(this).attr("checked")) {
                needsDetailIdStr.push($(this).val());
            }
        });

        if(!eachTrRadioChecked) {
            return;
        }

        if(!$.trim($("#remark").val())) {
            alert("请输入Shipmentid的运输方式，例如：空运或海运，这将会告诉仓库同事是否能拼箱子");
            return false;
        }

        $(this).attr("disabled", true);

        var pushWarehouseFlag = 0;
        if($(this).hasClass("pushWarehouseFlag")) {
            pushWarehouseFlag = 1;
        }

        $.ajax({
            url: "{:U('SingleShipmentidGrab/grabSubmit')}",
            type: 'post',
            async: true,
            data: {
                'accountId' : $("select[name='accountId']").val(),
                'shipmentid' : $("input[name='shipmentid']").val(),
                'needsDetailIdStr' : needsDetailIdStr,
                'shipToAddressDec' : shipToAddressDec,
                'pushWarehouseFlag' : pushWarehouseFlag,
                'remark' : $("#remark").val()
            },
            dataType: 'json',
            success: function (data) {
                layer.closeAll('loading');
                if(data.status==0) {
                    layer.msg(data.info);
                    return;
                }
                layer.msg(data.msg);
                window.location.href= '__URL__/index';
            }
        });
    });
</script>